<?php
/**
 * @author Jumper Swordwave
 * date: 2021/04/21
 */
declare(strict_types=1);
namespace App\Game\Model;

class Base
{
    /**
     * @var array
     * 保存属性数据
     */
    private $data;
    
    public function __construct(array $fills = [])
    {
        $this->fill($fills);
    }
    
    public function fill(array $fills = [])
    {
        foreach($fills as $key=>$val) {
            $this->data[$key] = $val;
        }
    }

    public function __set($key, $val)
    {
        $this->data[$key] = $val;
    }
    
    public function __get($key)
    {
        return isset($this->data[$key]) ? $this->data[$key] : null;
    }

    public function __isset($key)
    {
        return isset($this->data[$key]);
    }

    public function toArray() : array
    {
        return $this->data;
    }

    public function __serialize() : array 
    {
        return $this->toArray();
    }
    
    public function __unserialize(array $data) : void 
    {
        $this->data = $data;
    }
}